home *** CD-ROM | disk | FTP | other *** search
- <?php
-
- $hostname = "localhost";
- $database = "blog";
- $username = "root";
- $password = "root";
- $blog = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);
- mysql_select_db($database, $blog) or die("nao encontrou a BD");
- $query = "SELECT * FROM `posts` ORDER BY `ano` ASC, `mes` ASC, `dia` ASC";
- $posts = mysql_query($query, $blog) or die(mysql_error());
- $row_posts = mysql_fetch_assoc($posts);
-
- echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
- echo "<blog>";
-
- do{
- echo "<ano ano=\"".$row_posts['ano']."\">";
- echo " <mes mes=\"".$row_posts['mes']."\">";
- echo " <dia id=\"".$row_posts['id']."\" dia=\"".$row_posts['dia']."\" titulo=\"".$row_posts['titulo']."\" texto=\"".$row_posts['texto']."\">";
-
- $query = "SELECT * FROM `comentarios` WHERE `idPosts`=".$row_posts['id']." ORDER BY `ano` ASC, `mes` ASC, `dia` ASC";
- $comentarios = mysql_query($query, $blog) or die(mysql_error());
- $row_comentarios = mysql_fetch_assoc($comentarios);
- if($row_comentarios['id'] != ""){
- do{
- echo "<comentario ano=\"".$row_comentarios['ano']."\" mes=\"".$row_comentarios['mes']."\" dia=\"".$row_comentarios['dia']."\" nome=\"".$row_comentarios['nome']."\" texto=\"".$row_comentarios['texto']."\"/>";
- }while($row_comentarios = mysql_fetch_assoc($comentarios));
- }
- mysql_free_result($comentarios);
- echo " </dia>";
- echo " </mes>";
- echo "</ano>";
- }while($row_posts = mysql_fetch_assoc($posts));
-
- echo "</blog>";
- mysql_free_result($posts);
- mysql_close($blog);
- ?>